package query.select

import ast.statement.select.SqlSelectQuery
import database.DBConnection
import database.DB
import dsl.QuerySub
import query.BasedQuery

/**
 * 查询dsl接口
 * @property dbConnection DBConnection? 基础查询类
 */
interface SelectQuery : BasedQuery {
    /**
     * 获取sql语法树
     * @return SqlSelectQuery sql语法树
     */
    fun getSelect(): SqlSelectQuery

    /**
     * 获取数据库类型
     * @return DB 数据库类型
     */
    fun getDbType(): DB

    var dbConnection: DBConnection?

    /**
     * 生成union查询
     * @param select SelectQuery union右侧的查询dsl
     * @return UnionSelect union查询dsl
     */
    infix fun union(select: SelectQuery): UnionSelect

    /**
     * 生成union all查询
     * @param select SelectQuery union右侧的查询dsl
     * @return UnionSelect union查询dsl
     */
    infix fun unionAll(select: SelectQuery): UnionSelect

    /**
     * 生成except查询
     * @param select SelectQuery union右侧的查询dsl
     * @return UnionSelect union查询dsl
     */
    infix fun except(select: SelectQuery): UnionSelect

    /**
     * 生成intersect查询
     * @param select SelectQuery union右侧的查询dsl
     * @return UnionSelect union查询dsl
     */
    infix fun interSect(select: SelectQuery): UnionSelect

    /**
     * 将查询dsl转换为表达式类型，以作为子查询带入其他外层查询dsl
     * @return QuerySub 查询dsl用的子查询表达式
     */
    fun toExpr() : QuerySub
}